﻿using System;
using System.Collections.Generic;

using MiP.Common;

namespace MiP.Xml.Core.StringEvaluation
{
    public class StringEvaluator : IStringEvaluator
    {
        private readonly ILogger _logger;

        public StringEvaluator(ILogger logger)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");

            _logger = logger;
        }

        public IDictionary<string, string> Variables
        {
            get;
            set;
        }

        public string Evaluate(string sourceString)
        {
            if (string.IsNullOrWhiteSpace(sourceString))
                return sourceString;

            EvaluationContext context = new EvaluationContext(sourceString, Variables, _logger);

            return context.Evaluate();
        }
    }
}